<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">		
<html>								
<head>								
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">	
	<title> #macro </title>	
	<style type="text/css">		
	h1 {							
		font-size:28px;				
		font-family: verdana		
	}								
	p.otherNames{					
		font-size:20px;				
		font-family: verdana;		
	}								
	p.desc {						
		font-size:12px;				
		font-family: verdana;		
	}								
	p.doc {							
		margin-left:2cm;			
	}								
	td {						
		font-size:12px;				
		font-family: verdana;		
		vertical-align:text-top;	
		padding-top: 6px;			
		padding-bottom: 12px;		
	}								
	tr.title {						
		font-family: verdana;		
		font-size:14px;				
		font-weight:bold;			
		background-color: #CCCCFF ;	
	}								
	code.simpledesc {				
		font-size:15px;				
		color: #000099; 			
	}								
	</style>						
</head>							
<body>					
						
<h1> #macro </h1>	
<p class="desc">								
The #macro script element allows template designers to define a repeated segment of a VTL template. <br>
A "macro" accept any number of arguments (0..N) that can be used to produce the output.<br>
Macros are not functions, they are for rendering output (not for returning a value).<br>
<br>
<b>Examples : </b><br>
<br>
<br>

Macro with no arguments :<br>
<br>
<code>
&nbsp;&nbsp;&nbsp; ## ----------------------------------------------------------------------<br>
&nbsp;&nbsp;&nbsp; #macro( three )<br>
&nbsp;&nbsp;&nbsp; #set ( $result = "" )<br>
&nbsp;&nbsp;&nbsp; #foreach ( $i in [1..3] ) ${i}#end<br>
&nbsp;&nbsp;&nbsp; #end<br>
&nbsp;&nbsp;&nbsp; ## ----------------------------------------------------------------------<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; #three() ## No CR here (end of line) if no CR in the macro result<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; #three<br>
</code>
<br>
<br>

Macro with 2 arguments :<br>
<br>
<code>
&nbsp;&nbsp;&nbsp; ## ----------------------------------------------------------------------<br>
&nbsp;&nbsp;&nbsp; #macro( add $a1 $a2 )<br>
&nbsp;&nbsp;&nbsp; #set ( $r = $a1 + $a2 ) <br>
&nbsp;&nbsp;&nbsp; $a1 + $a2 = $r ## rendering = 20 + 3 = 23<br> 
&nbsp;&nbsp;&nbsp; #end<br>
&nbsp;&nbsp;&nbsp; ## ----------------------------------------------------------------------<br>
&nbsp;&nbsp;&nbsp; #add( 20, 3 )<br>
</code>
<br>
<br>

Macro with collection/array argument :<br>
<br>
<code>
&nbsp;&nbsp;&nbsp; ## ----------------------------------------------------------------------<br>
&nbsp;&nbsp;&nbsp; #macro( buildList $args )<br>
&nbsp;&nbsp;&nbsp; #set ( $count = 0 )<br>
&nbsp;&nbsp;&nbsp; #set ( $list = "" )<br>
&nbsp;&nbsp;&nbsp; #foreach( $a in $args )<br>
&nbsp;&nbsp;&nbsp; #set ( $count = $count + 1 )<br>
&nbsp;&nbsp;&nbsp; #if ( $count > 1 )<br>
&nbsp;&nbsp;&nbsp; #set ( $list = "${list}, " )<br>
&nbsp;&nbsp;&nbsp; #end<br>
&nbsp;&nbsp;&nbsp; #set ( $list = "${list} ${a}" )<br>
&nbsp;&nbsp;&nbsp; #end<br>
&nbsp;&nbsp;&nbsp; $list #end<br> 
&nbsp;&nbsp;&nbsp; ## ----------------------------------------------------------------------<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; A to D : #buildList( ['a','b','c','d'] )<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; Attributes : #buildList( $entity.attributes )<br>
</code>
<br>
<br>

"Function like call" getting the result as text (with quotes)<br>
<br>
<code>
&nbsp;&nbsp;&nbsp; #set( $list = "#buildList( ['a','b','c','d'] )" )<br>
&nbsp;&nbsp;&nbsp; list = $list<br>
</code>
<br>
<br>


</p>

<br>
<br>

</body>
</html>
